package com.controller;

import com.config.Result;
import com.pojo.User;
import com.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
public class LoginController {

    @Autowired
    UserServiceImpl service;



    @PostMapping(value = "/Login")
    public Result<?> Login(@RequestBody User user){
        System.out.println("进入此接口 ------------------------------------------------ ");
        User loginuser = service.selectUserByPassword(user);
        System.out.println("进入此接口 ======================================== "+ loginuser);
        if (loginuser == null){
            return Result.error("-1","用户名或密码错误");
        }else {
            System.out.println("搜索到的数据为------------------------------"+loginuser);
            return Result.success(loginuser);
        }
    }

    @PostMapping("/Register")
    public Result<?> Register(@RequestBody User user){

        User byId = service.findById(user);
        if (byId != null){
            return Result.error("-1","账号已存在");
        }

        Integer integer = service.insertData(user, "3");
        if (integer != 1){
            return Result.error("-1","注册失败");
        }
        return Result.success();
    }

}
